package com.example.demo;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.util.List;

public class LombokTest {
    /**
     * This method demonstrates(演示) the use of Lombok's @Builder annotation to create a request object
     *  * 使用 @Singular 注解实现添加单一元素到集合中
     */
    @Test
    public void testSingular() {
        AdsReportingRequest adsReportingRequest = AdsReportingRequest.builder()
                .query(RequestQuery.builder().queryName("query1").build())
                .query(RequestQuery.builder().queryName("query2").build())
                .build();
        Assertions.assertEquals(2, adsReportingRequest.getQueries().size());
    }

    @Test
    public void testWith() {
        AdsReportingRequest adsReportingRequest = AdsReportingRequest.builder()
            .query(RequestQuery.builder().queryName("query3").limit(10).build())
            .build();
        // 使用 withQueries 方法创建一个新的 AdsReportingRequest 对象，并且
        AdsReportingRequest newAdsReportingRequest = adsReportingRequest.withQueries(List.of());
        Assertions.assertTrue(newAdsReportingRequest.getQueries().isEmpty());

        // 使用 withQueryName 方法修改queryName，其他属性不变，并创建了一个新的 RequestQuery 对象
        RequestQuery query4 = adsReportingRequest.getQueries().get(0).withQueryName("query4");
        Assertions.assertEquals(10, query4.getLimit());
    }
}
